package sort.yht;

import sort.util.MySort;

/**
 * 功能描述：冒泡排序
 *
 * @Author: yht
 * @Date: 2021/8/11 14:11
 */
public class MaoPao implements MySort {

  @Override
  public String getName() {
    return "【冒泡排序】";
  }

  public int [] sort(int [] a){
    for(int i = 1; i < a.length - 1; i++) {
      for(int j = 0; j < a.length - i; j++) {
        if( a[j] > a[j+1] ) {
          int tmp = a[j];
          a[j] = a[j+1];
          a[j+1] = tmp;
        }
      }
    }
    return a;
  }

  public static void main(String[] args) {
    MaoPao mao = new MaoPao();
    mao.testAll();
  }
}
